<script type="text/javascript" language="javascript">
	
	function checkGo() {
		var operationType = getCheckedRadio('operationType');
		var complexity = getCheckedRadio('complexity');
		if(operationType == '') {
			alert('Please choose an operation');
			setFocus('operationType', 0);
			return;
		}
		if(complexity.length == '') {
			alert('Please choose complexity level');
			setFocus('complexity', 0);
			return;
		}
		submitForm('/arithmaticfractions.do?action=generate');
	}
	
	function setFocus(fieldname, index) {
		var obj = eval('document.' + getFormName() + '.' + fieldname + '[' + index + ']');
		obj.focus();
	}
	
   function processEnter(e, url) {
       if(e && e.keyCode == 13) {
    	   checkGo();
       }
    }
	
	function checkAnswer(url) {
    	var whole = eval('document.' + getFormName() + '.whole').value;
    	whole = isBlank(whole) ? '0' : whole;
    	var fraction = eval('document.' + getFormName() + '.fraction').value;
    	fraction = isBlank(fraction) ? '0' : fraction;
    	alert('Whole: ' + whole + '; Fraction: ' + fraction);
    		if(fraction != 0) {
    			//alert('Index: ' + fraction.indexOf('/'));
    			if (fraction.indexOf('/') != -1) {
        			var numdenom = fraction.split('/');
        			if(numdenom[0] == numdenom[1]) {
        				//useranswer = whole;
        				useranswer = (whole != 0) ? whole : 1;
        			}
        			useranswer = (whole != 0) ? whole + ' ' + fraction : fraction;
        			alert(useranswer);
        			//useranswer = whole + ' ' + fraction;
    			}
    			else {
    				alert('Please enter a valid fraction. \nexample. 1/4 or 3/7');
    				return;
    			}

    		}
    		else {
    			useranswer = whole;
    		}

    	//alert(useranswer);
	    var processedurl = '/lwf' + url + '&useranswer=' + useranswer;
	    retrieveURL(processedurl, 'answercheckblock');
	}
	
   function processAnswer(e, url) {
	   alert('url: ' + url);
       if(e && e.keyCode == 13) {
    	   checkAnswer(url);
       }
    }	
	
</script>